#include "cadscene.h"

static QStringList LIST_NAME = (QStringList() << "场景") ;

CADScene::CADScene(QObject *parent):CAudioControlDevice(parent)
{

}

void CADScene::addDevice(DEVICE_OPERATION *d)
{
    _device_list.append(d);
}

void CADScene::clearDevice()
{
    foreach (DEVICE_OPERATION *d, _device_list) {
        d->deleteLater();
    }

    _device_list.clear();
}

bool CADScene::containMainDeviceType(QString word)
{
    if(word.contains("灯") || word.length()>1)
        return true;
    else
        return false;
}

DEVICE_OPERATION * CADScene:: parseWord(QString word)
{
    QString op,name,value;

    //查找项目中的匹配设备
    foreach (DEVICE_OPERATION *s, _device_list) {
        QString abbr_name = s->_name.remove("场景");
        abbr_name = abbr_name.remove("模式");
        if(word.contains(abbr_name) && !containMainDeviceType(word.remove(abbr_name)))
        {
            name = s->_name;
            break;
        }
    }

    if(name.isEmpty())
    {
        return nullptr;
    }

    qDebug()<< "Audio: found device " << name;

    DEVICE_OPERATION *device_op = new DEVICE_OPERATION();
    device_op->_audio_name = name;
    device_op->_audio_operation = op;
    device_op->_audio_value = value;

    return device_op;
}

bool CADScene::actionAudionControl(DEVICE_OPERATION *devOp)
{
    devOp->_match = false;

    foreach (DEVICE_OPERATION *d, _device_list) {
        if(d->_name.contains(devOp->_audio_name) )
        {
            devOp->_id = d->_id;
            devOp->_name = d->_name;
            devOp->_match = true;

            return true;
        }
    }

    return false;
}
